package com.zxw.flow.controller.toc;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zxw.common.core.base.res.BasePageRes;
import com.zxw.common.core.base.res.BaseRes;
import com.zxw.flow.api.toc.FilePathApi;
import com.zxw.flow.domain.dto.FlowTypeDTO;
import com.zxw.flow.domain.dto.toc.FilePathDTO;
import com.zxw.flow.domain.dto.toc.FlowPathTreeDTO;
import com.zxw.flow.domain.entity.toc.FilePath;
import com.zxw.flow.domain.vo.toc.FilePathVO;
import com.zxw.flow.service.toc.FilePathService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-08-19
 */
@Api("流程图文件模块")
@RestController
@RequestMapping("/file-path")
@RequiredArgsConstructor
public class FilePathController implements FilePathApi {

    private final FilePathService filePathService;

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("流程图文件树")
    @GetMapping("/file-tree")
    public BaseRes<List<FlowPathTreeDTO>> findFileTree() {
        List<FlowPathTreeDTO> flowPathTreeDTOList = filePathService.getTree();
        return BaseRes.ok(flowPathTreeDTOList);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("根据主键id获取文件信息")
    @GetMapping("/{id}")
    public BaseRes<FilePathDTO> findFilePathById(@PathVariable("id") Long id) {
        FilePathDTO filePathDTO = filePathService.get(id);
        return BaseRes.ok(filePathDTO);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("添加文件")
    @PostMapping("/insert")
    public BaseRes<FilePath> insertFilePath(@RequestBody FilePathVO filePathVO) {
        FilePath filePath = filePathService.add(filePathVO);
        return BaseRes.okAdd(filePath);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("初始文件根目录")
    @PostMapping("init-file-path/{userAccount}")
    public BaseRes initFilePathData(@PathVariable("userAccount") String userAccount) {
        return BaseRes.ok(filePathService.init(userAccount));
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("修改文件")
    @PutMapping("/update/{id}")
    public BaseRes updateFilePath(@PathVariable("id") Long id, @RequestBody FilePathVO filePathVO) {
        filePathVO.setId(id);
        filePathService.update(filePathVO);
        return BaseRes.okUpdate();
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("删除文件")
    @DeleteMapping("/{id}")
    public BaseRes deleteFilePath(@PathVariable("id") Long id) {
        filePathService.delete(id);
        return BaseRes.okDelete();
    }


}
